repeat

 

repeat is a primitive that allows you to execute any set of commands n amount of times. For example, if you ask a turtle to repeat 10 [ forward 1 ] it will execute those commands 10 times back-to-back-to-back..., which will result in the turtle moving forward 10 units forward. You can use repeat in any context as long as it is within an ask command or outside an ask command. repeat can come especially handy in drawing shapes. For example, the following code would make the turtles draw a square:

 ask turtles [ 
  pen-down
    repeat 4 [ 
    forward 10
    right 90
  ]
]
 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the repeat primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Similar primitives:
pen-down

Starts tracing the movement of the turtle.

Read more
pen-up

Stops tracing a turtle's movement.

Read more
ask

a reporter that is used to make the agents in the agentset do something.

Read more
right

Turn a certain amount of degrees to the right.

Read more
 
Learn another primitive